package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

/**
 * @author stone
 * @date 2022/12/20 10:43
 */
public class LifeCycleBean1 implements BeanNameAware, BeanFactoryAware,
        InitializingBean, DisposableBean {

    String host;
    BeanFactory beanFactory; // 在当前这个组件中包含一个容器对象，一开始为null

    public void setHost(String host) {// 设置属性值的方法
        System.out.println("bean1的setHost方法");
        this.host = host;
    }

    public LifeCycleBean1() {
        System.out.println("bean1的实例化");
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("bean1的setBeanName:" + beanName);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("bean1的setBeanFactory方法");
        // 将容器传入进来
        this.beanFactory = beanFactory;
    }

    // 自定义的init方法需要指定
    public void customInit() {
        System.out.println("bean1的customInit");
    }
    // 自定义的destroy方法需要指定
    public void customDestroy() {
        System.out.println("bean1的customDestroy");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("bean1的afterPropertiesSet方法");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("bean1的destroy");
    }
}
